<?php
// SMS
class SMSAction extends Action {
	private $_uid = '';
	public function _initialize(){
		$this->_uid = session('uid');
		if(!$this->_uid) $this->display("Public:login");//(503,"对不起，您登录超时了，请重新登录！",1);
		//B('Authenticate', $action);
	}
    public function index(){
		echo substr_count('降到了附近的敏感词汇记录的分胡锦涛txwq.net温家宝',"胡锦涛");
		//$this->display("login");
    }
	public function smsSend(){
		$Inbox = M('Inbox');
		$param = $this->_param();
		
		$uid = $this->_uid;
		$hash = trim($param['hash']);
		$mobiles = trim($param['mobiles']);
		$smsContent = trim($param['sms_content']);
		$draft = $param['draft'];
		if($hash){
			if($param['send_way'] < 4 && $param['send_way']> 0){
				$sendWay = $param['send_way'];
			}else{
				$error = '发送通道错';
			}
			$designedTime = trim($param['designed_time']);
			
			$success_count = 0;
			$fail_count = 0;
			$preData = $Inbox->where("hash = '$hash'")->find();
			if($preData){
				$success_count = $preData['mobile_amount'];
				$fail_count = $preData['invalid_amount'];
				$preMobiles = $preData['mobiles'];
			
				$mobileArray = explode(",",$mobiles);
				$results = array();//结果集
				$isMobile = '';
				foreach($mobileArray as $m){
					$m = trim($m);
					if($m){
						if(isMobile($m)){
							//重复过滤
							if(in_array($m,$results)){
								$repeat++;
							}else{
								
								$results[] = $m;
								$isMobile .= $m.',';
								$success_count++;
							}
							
						}else{
							$notMobile .= $m.',';
							$fail_count++;
						}
					}
				}
				$mobiles = $preMobiles.','.$isMobile;
			}else{
				$success_count = 0;
				$fail_count = 0;
				$mobileArray = explode(",",$mobiles);
				$results = array();//结果集
				$isMobile = '';
				foreach($mobileArray as $m){
					$m = trim($m);
					if($m){
						if(isMobile($m)){
							//重复过滤
							if(in_array($m,$results)){
								$repeat++;
							}else{
								
								$results[] = $m;
								$isMobile .= $m.',';
								$success_count++;
							}
							
						}else{
							$notMobile .= $m.',';
							$fail_count++;
						}
					}
				}
				$mobiles = $isMobile;
			}
			$data = array(
				'owner_uid' => $uid,
				'hash' => $hash,
				'mobiles' => $mobiles,
				'sms_content' =>$smsContent,
				'mobile_amount' => $success_count,
				'invalid_amount' => $fail_count,
				'send_way' => $sendWay,
				'designed_time'=> "$designedTime",
				'create_time' => datetime(),
				'status' => $draft ? 0 : 1
			);
			//$dataJSON = json_encode($data);
			if($preData){
				unset($data['create_time']);
				$data['update_time'] = datetime();
				$v = $Inbox->where("hash = '$hash'")->save($data);
				$error = 1;
			}else{
				$v = $Inbox->add($data);
				$error = 2;
			}
			//$sql = $Inbox->getLastSql();
			if($v){
				$this->ajaxReturn(1,"发送成功",1);
			}else{
				$this->ajaxReturn(0,"发送失败",0);
			}
		}else{
			$this->assign('hash',genHash());
			$this->display();
		}
		
	}

	public function noSend(){
		$Model = M();
		$param = $this->_param();
		//dump($param);
		$where = array();
		$uid = $this->_uid;
		$param['account'] ? $where['B.account'] = $param['account']:1;
		$param['startdate'] ? $where['A.create_time'][] = array('EGT',$param['startdate']):1;//注意区间查询一定要这样哦
		$param['enddate'] ? $where['A.create_time'][] = array('ELT',$param['enddate']):1;
		$where['A.owner_uid'] = $uid;
		$where['A.status'] =  array('in',array('-1','0','1','2'));
		import('ORG.Util.Page');// 导入分页类
		$count      = $Model->table('sms_inbox A')->join('sms_account B ON A.owner_uid = B.uid')->where($where)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		
		$results = $Model->table('sms_inbox A')->join('sms_account B ON A.owner_uid = B.uid')->field('A.*,B.uid,B.account')->where($where)->order('A.inbox_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		//echo $Model->getLastSql();//打印sql语句
	
		
		foreach($results as $key=>$v){
			if($v['mobiles']){
				$results[$key]['mobiles'] = substr($v['mobiles'],0,23)." 等";
			}
		}
		$this->assign('page',$show);
		$this->assign('list',$results);
		$this->display();
	}
	public function alreadySend(){
		$Model = M();
		$param = $this->_param();
		//dump($param);
		$uid = $this->_uid;
		$where = array();
		$param['account'] ? $where['B.account'] = $param['account']:1;
		$param['startdate'] ? $where['A.create_time'][] = array('EGT',$param['startdate']):1;//注意区间查询一定要这样哦
		$param['enddate'] ? $where['A.create_time'][] = array('ELT',$param['enddate']):1;
		$where['A.owner_uid'] = $uid;
		$where['A.status'] = 3;// array('in',array('-1','0','1','2'));
		import('ORG.Util.Page');// 导入分页类
		$count      = $Model->table('sms_inbox A')->join('sms_account B ON A.owner_uid = B.uid')->where($where)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		
		$results = $Model->table('sms_inbox A')->join('sms_account B ON A.owner_uid = B.uid')->field('A.*,B.uid,B.account')->where($where)->order('A.create_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		//echo $Model->getLastSql();//打印sql语句
	
		
		foreach($results as $key=>$v){
			if($v['mobiles']){
				$results[$key]['mobiles'] = substr($v['mobiles'],0,23)." 等";
			}
		}
		$this->assign('page',$show);
		$this->assign('list',$results);
		$this->display();
	}
	//短信垃圾箱
	public function dustbin(){
		$Model = M();
		$param = $this->_param();
		//dump($param);
		$where = array();
		$uid = $this->_uid;
		$param['account'] ? $where['B.account'] = $param['account']:1;
		$param['startdate'] ? $where['A.create_time'][] = array('EGT',$param['startdate']):1;//注意区间查询一定要这样哦
		$param['enddate'] ? $where['A.create_time'][] = array('ELT',$param['enddate']):1;
		$where['A.owner_uid'] = $uid;
		$where['A.status'] = -1;
		import('ORG.Util.Page');// 导入分页类
		$count      = $Model->table('sms_inbox A')->join('sms_account B ON A.owner_uid = B.uid')->where($where)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		
		$results = $Model->table('sms_inbox A')->join('sms_account B ON A.owner_uid = B.uid')->field('A.*,B.uid,B.account')->where($where)->order('A.create_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		//echo $Model->getLastSql();//打印sql语句
	
		
		foreach($results as $key=>$v){
			if($v['mobiles']){
				$results[$key]['mobiles'] = substr($v['mobiles'],0,23)." 等";
			}
		}
		$this->assign('page',$show);
		$this->assign('list',$results);
		$this->display();
	}
	//短信垃圾箱
	public function draft(){
		$Model = M();
		$param = $this->_param();
		//dump($param);
		$where = array();
		$uid = $this->_uid;
		$param['account'] ? $where['B.account'] = $param['account']:1;
		$param['startdate'] ? $where['A.create_time'][] = array('EGT',$param['startdate']):1;//注意区间查询一定要这样哦
		$param['enddate'] ? $where['A.create_time'][] = array('ELT',$param['enddate']):1;
		$where['A.owner_uid'] = $uid;
		$where['A.status'] = 0;
		import('ORG.Util.Page');// 导入分页类
		$count      = $Model->table('sms_inbox A')->join('sms_account B ON A.owner_uid = B.uid')->where($where)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		
		$results = $Model->table('sms_inbox A')->join('sms_account B ON A.owner_uid = B.uid')->field('A.*,B.uid,B.account')->where($where)->order('A.create_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		//echo $Model->getLastSql();//打印sql语句
	
		
		foreach($results as $key=>$v){
			if($v['mobiles']){
				$results[$key]['mobiles'] = substr($v['mobiles'],0,23)." 等";
			}
		}
		$this->assign('page',$show);
		$this->assign('list',$results);
		$this->display();
	}

	public function smsDelete(){
	    $Inbox = M('Inbox');
		$uid = $this->_uid;
		$param = $this->_param();
		if($param['inbox_id']){
			$data = array(
				'status' => -1	
			);
			$v = $Inbox->where("owner_uid = $uid AND inbox_id = {$param['inbox_id']}")->save($data);
			if($v){
				$this->ajaxReturn(1,"删除成功",1);
			}else{
				$this->ajaxReturn(0,"删除失败",0);
			}
		}else{
			$this->ajaxReturn(2,"参数非法",0);
		}
		
	} // end func
	
	/**
	 * Short description.
	 * @param   type    $varname    description
	 * @return  type    description
	 * @access  public or private
	 * @static  makes the class property accessible without needing an instantiation of the class
	 */
	function smsDetail(){
		$Inbox = M('Inbox');
		$uid = $this->_uid;
		$get = $this->_get();
		if($get['inbox_id']){
			$v = $Inbox->where("owner_uid = $uid AND inbox_id = {$get['inbox_id']}")->find();
			$this->assign('list',$v);
			$this->display();
		}else {
		    $this->ajaxReturn(2,"参数错误",0);
		}
	} // end func
	public function checkBlackword(){
	    $param = $this->_param();
		$Blackwords = M('Blackwords');
		$content = trim($param['word']);////urldecode($_GET['word']);
		$keywords = $Blackwords->where('status = 1')->select();
		$warn = array();
		foreach($keywords as $v){
			$is = substr_count($content,trim($v['keyword']));
			if($is > 0){
				$warn[] = $v['keyword'];
			}
		}
		if(empty($warn)){
			$this->ajaxReturn(0,"没有敏感词汇",0);
		}else{
			$string = '';
			foreach($warn as $v){
				$string .= $v.',';
			}
			$this->ajaxReturn($string,"含有敏感词汇",1);
		}
	}
	//添加常用短信
	public function smsTemplateAdd(){
		$PT = M('PublicTemplate');
		$uid = $this->_uid;
		$category_id = $this->_get('category_id');
		$sms_content = $this->_get('sms_content');
		if($sms_content){
			$data = array(
					'owner_uid' => $uid,
					'sms_content' => $sms_content,
					'category_id' => $category_id ? $category_id : 0,
					'create_time' => datetime(),
					'update_time' => datetime(),
					'status' => 1
			);
			$v = $PT->add($data);
			if($v){
				$this->ajaxReturn($v,"添加成功",1);
			}else{
				$this->ajaxReturn(0,"添加失败",0);
			}
		}else{
			$this->ajaxReturn(0,"信息不全",0);
		}
		
	}
	//编辑常用短信
	public function smsTemplateAddEdit(){
		$PT = M('PublicTemplate');
		$uid = $this->_uid;
		$category_id = $this->_get('category_id');
		$sms_content = $this->_get('sms_content');
		if($category_id && $sms_content){
			$data = array(
					'uid' => $uid,
					'sms_content' => $sms_content,
					'category_id' => $category_id,
					'update_time' => 'now()',
					'status' => 1
			);
			$v = $CATE->where('uid = $uid')->save($data);
			if($v){
				$this->ajaxReturn($v,"短信分类如下",1);
			}else{
				$this->ajaxReturn(0,"短信分类为空",0);
			}
		}else{
			$this->ajaxReturn(0,"信息不全",0);
		}
		
	}
	//短信分类查询
	public function smsTemplateCate(){
		$CATE = M('TemplateCategory');
		$uid = $this->_uid;
	
		$v = $CATE->where('uid = $uid')->select();
		if($v){
			$this->ajaxReturn($v,"短信分类如下",1);
		}else{
			$this->ajaxReturn(0,"短信分类为空",0);
		}
	}
	//短信分类修改
	public function smsTemplateCateEdit(){
		$cat = $this->_get("sms_category");
		$CATE = M('TemplateCategory');
		$uid = $this->uid;
		$cat = trim($cat);
		if($cat == ''){
			$this->ajaxReturn(0,"修改分类不能为空",0);
		}else{
			$data = array(
					'uid' => $uid,
					'category_content' => $cat,
					'create_time' => 'now()',
					'status' => 1
			);
			$v = $CATE->where('uid = $uid')->save($data);
			if($v){
				$this->ajaxReturn(1,"修改成功",1);
			}else{
				$this->ajaxReturn(0,"修改失败",0);
			}
		}
	}
	//短信分类删除
	public function smsTemplateCateDelete(){
		$cat = $this->_get("sms_category");
		$CATE = M('TemplateCategory');
		$uid = $this->uid;
		if($cat != ''){
			$tempCate = $CATE->where("uid = $uid AND category_content = '$cat'")->delete();
			if($v){
				$this->ajaxReturn(1,"删除成功",1);
			}else{
				$this->ajaxReturn(0,"删除失败",0);
			}
		}else{
			$this->ajaxReturn(0,"获取分类出错，导致删除失败",0);
		}
	}
	//短信分类添加
	public function smsTemplateCateAdd(){
		$cat = $this->_get("sms_category");
		$CATE = M('TemplateCategory');
		$uid = $this->uid;
		if($cat == ''){
			$is = $CATE->where("uid = $uid AND category_content = '$cat'")->find();
			if($is){
				$this->ajaxReturn(0,"该分类已经存在！",0);
			}
			$data = array(
					'uid' => $uid,
					'category_content' => $cat,
					'create_time' => 'now()',
					'status' => 1
			);
			$v = $CATE->where('uid = $uid')->add($data);
			if($v){
				$this->ajaxReturn(1,"添加成功",1);
			}else{
				$this->ajaxReturn(0,"添加失败",0);
			}
		}else{
			$this->ajaxReturn(0,"分类为空",0);
		}
	}
	
	public function smsTemplate(){
		$PubTemp = M('PublicTemplate');
		$CATE = M('TemplateCategory');
		$uid = $this->uid;
		$param = $this->_param();
		if($param['category_id']){
			$cate = $CATE->where("owner_uid = 0 AND parent_id = 1")->select();
			$list = $PubTemp->where("category_id = ".intval($param['category_id']))->select();
			$this->assign('list',$list);
			$this->assign('sms_category',$cate);	
		}else{
			$cate = $CATE->where("owner_uid = 0 AND parent_id = 1")->select();
		
			//$results = $PubTemp->select();
			$privateResults = $PubTemp->where("owner_uid = $uid")->select();
			$this->assign('private',$privateResults);
			$this->assign('list',$results);
			$this->assign('sms_category',$cate);	
		}
		
		$this->display();
	}
	
	/**
	 * Short description.
	 * @param   type    $varname    description
	 * @return  type    description
	 * @access  public or private
	 * @static  makes the class property accessible without needing an instantiation of the class
	 */
	public function smsTemplateInsert()
	{
	    $PubTemp = M('PublicTemplate');
		$CATE = M('TemplateCategory');
		$uid = $this->_uid;
		$param = $this->_param();
		if($param['category_id']){
			$cate = $CATE->where("owner_uid = 0 AND parent_id = 1")->select();
			$list = $PubTemp->where("category_id = ".intval($param['category_id']))->select();
			$this->assign('list',$list);
			$this->assign('cate',$cate);	
		}else{
			$cate = $CATE->where("owner_uid = 0 AND parent_id = 1")->select();
			//$results = $PubTemp->select();
			$privateResults = $PubTemp->where("owner_uid = $uid")->select();
			$this->assign('cate',$cate);
			$this->assign('list',$privateResults);
			
		}
		
		$this->display();
	} // end func
	/**
	 * Short description.
	 * @param   type    $varname    description
	 * @return  type    description
	 * @access  public or private
	 * @static  makes the class property accessible without needing an instantiation of the class
	 */
	public function checkPhone()
	{ echo datetime();
		$file = "phone.txt";
	    $lines = file_get_contents($file);
		ini_set('memory_limit', '-1');//不要限制Mem大小，否则会报错
		$line=explode("\n",$lines);
		echo count($line);
		
		$i=0;
		$results = array();
		foreach($line as $v){
			$v = trim($v);
			if(isMobile($v)){
				if(in_array($v,$results)){
					
				}else{
					$i++;
					$results[] = $v;
				}
				
			}else{
				echo 'error';
			}
		}
		echo $i;
		echo count($results);
		echo datetime();
	} // end func
	
	/**
	 * Short description.
	 * @param   type    $varname    description
	 * @return  type    description
	 * @access  public or private
	 * @static  makes the class property accessible without needing an instantiation of the class
	 */
	public function geneRamPhone()
	{			
			$file = "phone.txt";
	 
			if (is_writable($file) == false) {
				//文件不存在 ，则新建文件
				
				$fp=fopen($file, "w+"); //打开文件指针，创建文件
				if(!is_writable($file)){
					 // die("文件:" .$file. "不可写，请检查！");
				}else{
					$string = '';
					for($i = 15226190000 ;$i< 1522619020;$i++){
						$string = $string ."$i\r\n";
					
					}
					echo "感谢您的订阅！我们一上线就会马上通知您的1！";
					fwrite($file, $string);
					fclose($fp); 
				}
				//
			} else {
				echo "感谢您的订阅！我们一上线就会马上通知您的2！";
				$data = file_get_contents($file);
				for($i = 15226190000 ;$i< 15227200000;$i++){
						$string .= "$i\r\n";
					
					}
				 
					//echo $string;
					$data.=$string;
				//$data .= "$email|$ip|$date\r\n";
				file_put_contents ($file, $data);
			}
	

	} // end func
	/**
	 * 导出号码到txt文件
	 * @param   type    $uid    description
	 * @return  type    $inbox_id
	 * @access  public
	 * @static  makes the class property accessible without needing an instantiation of the class
	 */
	public function exportPhoneTxt()
	{		import('ORG.Net.Http');	
			$Inbox = M('Inbox');
			$ExportRecords = M('ExportRecords');
			$Http = new Http();
			$param = $this->_param();
			$uid = $this->_uid;
			$time = time();
			$file = "./Uploads/files/export/$time.txt";

			$inboxID = intval($param['inbox_id']);

			$results = $Inbox->where("inbox_id = $inboxID")->find();
			if($results){
				if (is_writable($file) == false) {
					//文件不存在 ，则新建文件
					
					$fp=fopen($file, "w+"); //打开文件指针，创建文件
					if(!is_writable($file)){
						  die("文件:" .$file. "不可写，请检查！");
					}else{
						$string = '';
						//echo $results['mobiles'];
						$resultsArray = explode(',',$results['mobiles']);
						$count = 0;
						foreach($resultsArray as $v){
							if(trim($v)){
							    $string .= $v."$i\r\n";
								$count++;
							}
							
						
						}
						//dump($resultsArray);
						//echo $string;
						
						$v = fwrite($fp, $string);
						$data = array(
							'owner_uid' => $uid,
							'inbox_id' => $inboxID,
							'export_file'=>$file,
							'mobile_count' => $count,
							'create_time' => datetime(),
							'status' => 1
						);
						if($v){
							$v = $ExportRecords->add($data);
							if($v) logs($uid,'导出手机号码成功并记录成功',1,'inbox_id:'.$inboxID."count:$count");
							else logs($uid,'导出手机号码成功但记录失败',0,'inbox_id:'.$inboxID);
						}else{
							$data['status'] = 0;
							$v = $ExportRecords->add($data);
							if($v) logs($uid,'导出手机号码失败但记录成功',0,'inbox_id:'.$inboxID);
							else logs($uid,'导出手机号码失败并记录失败',0,'inbox_id:'.$inboxID);
						}
						fclose($fp);
						$Http->download($file,$results['inbox_id']);
						
					}
					//
				} else {
					$error = "文件目录不可写";
				}
			}else{
				$error = '不存在该数据';
			
			}
			$this->ajaxReturn($inboxID,$error,0);
	

	} // end func
	
	/**
	 * 从导入的号码中提取手机号码
	 * @param   type    $varname    description
	 * @return  type    description
	 * @access  public or private
	 * @static  
	 */

	public function importFile(){
		import('ORG.Net.UploadFile');
		$upload = new UploadFile();// 实例化上传类
		$upload->maxSize  = 100000000 ;// 设置附件上传大小
		$upload->allowExts  = array('txt', 'xls');// 设置附件上传类型
		$upload->savePath =  './Uploads/files/import/';// 设置附件上传目录
		$upload->saveRule = 'time';
		$upload->autoCheck = true;
		if(!$upload->upload()) {// 上传错误提示错误信息
			$this->error($upload->getErrorMsg());
		}else{// 上传成功 获取上传文件信息
			//print("上传成功");
			$info =  $upload->getUploadFileInfo();   //$info[0]['savename'];
		}
		$hash = trim($_GET['hash']);
		if(!$hash){
			$data = array(
				'data'   => '',
				'info'   => '参数出错',
				'status' => 0,
			);
			echo json_encode($data);
			exit;
		}
		$filename = $info[0]['savename'];
		//进行处理
		$file = $upload->savePath.$info[0]['savename'];//'words.txt';//10W条记录的TXT源文件
		$lines = file_get_contents($file);
		ini_set('memory_limit', '-1');//不要限制Mem大小，否则会报错
		$line=explode("\n",$lines);
		$all_count = count($line);//记录导入的数据的总号码数据量
		$all_count = $all_count?$all_count:0; //echo $all_count;
		//如果文件过大，先对文件进行切割 ，每个文件10万行数据
		$prefixFile = date("YmdHis");
		if($all_count > 1000000){
			$cut_count = ceil($all_count/1000000);//总共输出的文件数
			$fn_in = $file;//你要切割的大文件
			$fn_out = $prefixFile.'_';//输出文件的前缀
			$i=0;//当前文件已经输出的行数
			$n=1;
			$fp_in=fopen($fn_in,'r');	

			while (!feof($fp_in)){//not end
				if($i==0){
					//echo './Uploads/files/'.$fn_out.$n.'.txt';
					$fp_out=fopen('./Uploads/files/'.$fn_out.$n.'.txt','w');
				}
			    $outLine=fgets($fp_in);
				
				if(fputs($fp_out,$outLine)){//echo "success!";
				}
			    $i++;
				if($i==100000){
				  fclose($fp_out); 
				  $i=0; 
				  $n++;
				}
			}
			if($i == $cut_count){
				fclose($fp_in); 
				$i=0;
			}
			
		}
		//$per_amount = floor($all_count / 100);
		$success_count = 0;
		$fail_count = 0;
		$notMobile = '';
		$isMobile = '';
		$INBOX = M('Inbox');
		$results = array();
		$repeat = 0;
		session('processing',0);
		foreach($line as $key =>$li)
		{	
			//if(($key % $per_amount) == 0 && $key > 0 ){
			//	session('processing',$key/$per_amount);
			//}
			$li = intval(trim($li));
			$i++;
			if($li){
				if(isMobile($li)){
					//重复过滤
					//if(in_array($li,$results)){
					//	$repeat++;
					//}else{
						
						//$results[] = $li;
						$isMobile .= $li.',';
						$success_count++;
					//}
					
				}else{
					$notMobile .= $li.',';
					$fail_count++;
				}
			}
		}
		//echo 's'.$success_count."s";echo $fail_count;
		//echo $notMobile;
		$data = array(
			'owner_uid' => $uid,
			'mobiles'	=> trim(',',$isMobile),
			'hash'		=> $hash,
			'source_file' => $filename,
			'mobile_amount' => $success_count,
			'invalid_amount' => $fail_count,
			'create_time'	=> datetime()
		);
		//$sql="INSERT INTO sms_inbox (filename,text,all_count,success,success_count,fail,fail_count,create_time) VALUES('$filename','$lines','$all_count','$isMobile','$success_count','$notMobile','$fail_count',now())";
		$inbox_id = $INBOX->add($data);
		if($inbox_id){
			$data = array(
				'data'   => array('success'=>$success_count,'fail'=>$fail_count,'mobiles' => $isMobile,'inbox_id' => $inbox_id),
				'info'   => '上传成功',
				'status' => 1,
			);
			echo json_encode($data); //(1,"上传成功",1);
			//echo "总共发现[$all_count]个手机号码，成功导入[$success_count]个到数据库中,失败[$fail_count]个,重复{$repeat}个";//$this->success();
		}else{
			$data = array(
				'data'   => array('success'=>$success_count,'fail'=>$fail_count,'mobiles' => $isMobile,'inbox_id' => $inbox_id),
				'info'   => '上传失败'.$INBOX->getLastSql(),//$isMobile,
				'status' => 0,
			);
			echo json_encode($data);
		
		}
		//echo $INBOX->getLastSql();
//		if($i>=20000&&$i<25000)//分批次导入，避免失败
//		{
//		$mm=explode(" ",$arr[4]);
//		foreach($mm as $m) //【adductive#1 adducting#1 adducent#1】这一个TXT记录要转换为3个SQL记录 {
//		$nn=explode("#",$m);
//		$word=$nn[0];
//		$sql.="(\"$word\",1,$senti_value,2),";//这个地方要注意到是 word有可能包含单引号（如jack's），因此我们要用双引号来包含word（注意转义）
//		}
//		}
//		$i++;
//		}
//
//		//echo $i;
//		$sql= substr($sql,0,-1);//去掉最后一个逗号
//		//echo $sql;
//		file_put_contents('20000-25000.txt', $sql); //批量导入数据库，5000条一次，大概需要40秒的样子；一次导入太多max_execution_time会不够，导致失败
	}
}